<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nginx负载均衡技术深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 8px;
            margin-top: -8px;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 15px;
            color: white;
            font-size: 24px;
            margin-bottom: 20px;
        }
        
        .strategy-card {
            background: white;
            border-radius: 20px;
            padding: 30px;
            position: relative;
            overflow: hidden;
        }
        
        .strategy-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 5px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">
                    Nginx负载均衡技术深度解析
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    探索高性能Web服务器的负载均衡艺术，构建稳定可靠的现代互联网架构
                </p>
                <div class="mt-10 flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-server text-3xl mb-2"></i>
                        <p class="text-sm">高性能</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-3xl mb-2"></i>
                        <p class="text-sm">高可用</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-chart-line text-3xl mb-2"></i>
                        <p class="text-sm">可扩展</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <div class="bg-white rounded-3xl shadow-xl p-10 card-hover">
                    <p class="text-lg leading-relaxed text-gray-700">
                        <span class="drop-cap">N</span>ginx 是一款高性能的 Web 服务器，广泛用于负载均衡、反向代理和HTTP缓存等场景。作为一种轻量级的负载均衡器，Nginx 在分发客户端请求到后端服务器的过程中扮演着重要的角色。它具有极高的吞吐量、低延迟和较少的资源消耗，成为了现代互联网架构中常见的选择。
                    </p>
                </div>
            </div>
        </div>
    </section>

    <!-- Core Concepts Section -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-4xl font-bold text-center mb-12 text-gradient">核心概念与原理</h2>
                
                <!-- 负载均衡基本概念 -->
                <div class="mb-16">
                    <h3 class="text-2xl font-bold mb-8 section-title">1. 负载均衡的基本概念</h3>
                    <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                        负载均衡指的是将客户端请求分发到多个服务器（通常是后端应用服务器或数据库服务器）上，从而实现以下目标：
                    </p>
                    
                    <div class="grid md:grid-cols-3 gap-6">
                        <div class="bg-white p-6 rounded-2xl shadow-lg card-hover">
                            <div class="feature-icon">
                                <i class="fas fa-heartbeat"></i>
                            </div>
                            <h4 class="text-xl font-bold mb-3">提升应用的可用性和容错性</h4>
                            <p class="text-gray-600">如果某台服务器故障，负载均衡器能够将请求转发到其他健康的服务器。</p>
                        </div>
                        
                        <div class="bg-white p-6 rounded-2xl shadow-lg card-hover">
                            <div class="feature-icon">
                                <i class="fas fa-rocket"></i>
                            </div>
                            <h4 class="text-xl font-bold mb-3">提升并发处理能力</h4>
                            <p class="text-gray-600">通过分发请求，避免单一服务器的过载，充分利用多台服务器的计算资源。</p>
                        </div>
                        
                        <div class="bg-white p-6 rounded-2xl shadow-lg card-hover">
                            <div class="feature-icon">
                                <i class="fas fa-tachometer-alt"></i>
                            </div>
                            <h4 class="text-xl font-bold mb-3">减少响应延迟</h4>
                            <p class="text-gray-600">通过就近的服务器响应请求，提高访问速度。</p>
                        </div>
                    </div>
                </div>

                <!-- 工作原理 -->
                <div class="mb-16">
                    <h3 class="text-2xl font-bold mb-8 section-title">2. Nginx负载均衡的工作原理</h3>
                    <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                        Nginx实现负载均衡的基本工作流程是：
                    </p>
                    
                    <div class="mermaid">
                        graph LR
                            A[客户端] -->|发起请求| B[Nginx负载均衡器]
                            B -->|选择策略| C{负载均衡策略}
                            C -->|轮询| D[服务器1]
                            C -->|IP哈希| E[服务器2]
                            C -->|最少连接| F[服务器3]
                            D -->|响应| B
                            E -->|响应| B
                            F -->|响应| B
                            B -->|返回结果| A
                            
                            style A fill:#f9f,stroke:#333,stroke-width:2px
                            style B fill:#667eea,stroke:#333,stroke-width:2px,color:#fff
                            style C fill:#764ba2,stroke:#333,stroke-width:2px,color:#fff
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Load Balancing Strategies -->
    <section class="py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-4xl font-bold text-center mb-12 text-gradient">负载均衡策略详解</h2>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <!-- 轮询 -->
                    <div class="strategy-card card-hover">
                        <h4 class="text-xl font-bold mb-4 flex items-center">
                            <i class="fas fa-sync-alt mr-3 text-purple-600"></i>
                            轮询（Round-robin）
                        </h4>
                        <p class="text-gray-700 mb-4">
                            这是Nginx的默认负载均衡策略。在该策略下，Nginx会按照顺序依次将请求转发给每个后端服务器。请求是平均分配到各个后端服务器上的。
                        </p>
                        <div class="flex space-x-4">
                            <div class="flex-1">
                                <p class="text-sm font-semibold text-green-600 mb-2">
                                    <i class="fas fa-check-circle mr-1"></i> 优点
                                </p>
                                <p class="text-sm text-gray-600">简单、易于实现，适合服务器性能相近的场景。</p>
                            </div>
                            <div class="flex-1">
                                <p class="text-sm font-semibold text-red-600 mb-2">
                                    <i class="fas fa-times-circle mr-1"></i> 缺点
                                </p>
                                <p class="text-sm text-gray-600">没有考虑服务器负载，可能导致某些服务器过载。</p>
                            </div>
                        </div>
                    </div>

                    <!-- 最少连接 -->
                    <div class="strategy-card card-hover">
                        <h4 class="text-xl font-bold mb-4 flex items-center">
                            <i class="fas fa-link mr-3 text-purple-600"></i>
                            最少连接（Least Connections）
                        </h4>
                        <p class="text-gray-700 mb-4">
                            该策略将请求转发给当前连接数最少的后端服务器。Nginx会定期检查每台服务器的连接数，选择连接数最少的服务器来处理新的请求。
                        </p>
                        <div class="flex space-x-4">
                            <div class="flex-1">
                                <p class="text-sm font-semibold text-green-600 mb-2">
                                    <i class="fas fa-check-circle mr-1"></i> 优点
                                </p>
                                <p class="text-sm text-gray-600">适用于后端服务器处理请求的时间差异较大的场景。</p>
                            </div>
                            <div class="flex-1">
                                <p class="text-sm font-semibold text-red-600 mb-2">
                                    <i class="fas fa-times-circle mr-1"></i> 缺点
                                </p>
                                <p class="text-sm text-gray-600">可能会对某些请求量很小但频繁的服务器造成不公平的负载。</p>
                            </div>
                        </div>
                    </div>

                    <!-- IP哈希 -->
                    <div class="strategy-card card-hover">
                        <h4 class="text-xl font-bold mb-4 flex items-center">
                            <i class="fas fa-hashtag mr-3 text-purple-600"></i>
                            IP哈希（IP Hash）
                        </h4>
                        <p class="text-gray-700 mb-4">
                            Nginx通过客户端的IP地址来计算哈希值，根据哈希值决定请求应该转发到哪一台后端服务器。保证了来自同一IP的请求始终会被转发到同一台服务器。
                        </p>
                        <div class="flex space-x-4">
                            <div class="flex-1">
                                <p class="text-sm font-semibold text-green-600 mb-2">
                                    <i class="fas fa-check